#region Usings

using Karma.Framework.Core.Domain.Tools.Import.Data;

#endregion

namespace Karma.Framework.Core.Domain.Tools.Import.Extension
{
    internal class EntityPersisterAdapter
    {
        public EntityPersisterAdapter(IEntityPersisterListener listener)
        {
            Listener = listener;
        }

        private IEntityPersisterListener Listener { get; set; }

        public void OnBeforePersistAll(object o, BeforePersistAllEntitiesEventArgs e)
        {
            if (Listener.CanApplyTo(e.TargetType))
            {
                Listener.OnBeforePersistAll(e.Entities);
            }
        }

        public void OnAfterPersistAll(object o, AfterPersistAllEntitiesEventArgs e)
        {
            if (Listener.CanApplyTo(e.TargetType))
            {
                Listener.OnAfterPersistAll(e.Entities);
            }
        }

        public void OnBeforePersistEntity(object o, BeforePersistEntityEventArgs e)
        {
            if (Listener.CanApplyTo(e.TargetType))
            {
                Listener.OnBeforePersist(e.Entity);
            }
        }

        public void OnAfterPersistEntity(object o, AfterPersistEntityEventArgs e)
        {
            if (Listener.CanApplyTo(e.TargetType))
            {
                Listener.OnAfterPersist(e.Entity);
            }
        }

        public void OnBeforeUpdateEntity(object o, BeforePersistEntityEventArgs e)
        {
            if (Listener.CanApplyTo(e.TargetType))
            {
                Listener.OnBeforeUpdate(e.Entity);
            }
        }

        public void OnAfterUpdateEntity(object o, AfterPersistEntityEventArgs e)
        {
            if (Listener.CanApplyTo(e.TargetType))
            {
                Listener.OnAfterUpdate(e.Entity);
            }
        }
    }
}